home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1999
/
MacHack 1999.toast
/
The Hacks
/
DesktopDoubler
/
NubApp
/
Event.cc
next >
Wrap
Text File
|
1999-06-23
|
6KB
|
387 lines
#define DISABLE_LOCAL_CALLTRACE 1 // Set to 1 to disable Call Traces for this file.
#define DISABLE_LOCAL_DEBUG 0 // Set to 1 to disable all debugging for this file.
#include "DebugUtils.h"
#include <Dialogs.h>
#include "Event.h"
#include "Main.h"
#include "Menu.h"
#include "Window.h"
#ifdef __cplusplus
extern "C" {
#endif
static pascal OSErr AECoreHandler(AppleEvent *aevent,AppleEvent *areply,long refcon);
static OSStatus AEGotRequiredParams(AppleEvent *aevent);
#ifdef __cplusplus
}
#endif
extern MenuManager *gMenuManager;
extern WindowManager *gWindowManager;
void BaseEventManager::DoDispatch(EventRecord *event)
{
if ((event->what != nullEvent) && (event->what != osEvt) && IsDialogEvent(event) &&
!((event->what == keyDown) && (event->modifiers & cmdKey)))
{
HandleDialogEventDispatch(event);
}
else
{
switch(event->what)
{
case nullEvent:
HandleNullEventDispatch(event);
break;
case mouseDown:
HandleMouseDownDispatch(event);
break;
case mouseUp:
HandleMouseUpDispatch(event);
break;
case keyDown:
HandleKeyDownDispatch(event);
break;
case keyUp:
HandleKeyUpDispatch(event);
break;
case autoKey:
HandleAutoKeyDispatch(event);
break;
case updateEvt:
HandleUpdateEvtDispatch(event);
break;
case activateEvt:
HandleActivateEvtDispatch(event);
break;
case osEvt:
HandleOSEvtDispatch(event);
break;
case kHighLevelEvent:
HandleHighLevelEventDispatch(event);
break;
}
}
}
void BaseEventManager::HandleNullEventDispatch(EventRecord *event)
{
gWindowManager->DoIdleTime(event,event->where,event->modifiers);
gMenuManager->DoMenuUpdates();
}
void BaseEventManager::HandleMouseDownDispatch(EventRecord *event)
{
WindowPtr window;
SInt32 part;
Window *win;
part = FindWindow(event->where,&window);
switch(part)
{
case inDesk:
break;
case inMenuBar:
HandleInMenuBarDispatch(event);
break;
case inSysWindow:
SystemClick(event,window);
break;
case inContent:
case inDrag:
case inGrow:
case inGoAway:
case inZoomIn:
case inZoomOut:
gWindowManager->DoClick(event->where,event->modifiers,window,part);
break;
}
}
void BaseEventManager::HandleMouseUpDispatch(EventRecord *event)
{
}
void BaseEventManager::HandleKeyDownDispatch(EventRecord *event)
{
UInt32 selection;
UInt32 key;
Window *win;
key = charCodeMask & event->message;
// Resolve menu item command keys
if (event->modifiers & cmdKey)
{
gMenuManager->DoMenuUpdates();
selection = MenuKey(key);
if ((selection >> 16) != 0)
{
gMenuManager->DoSelect((selection >> 16),(selection & 0xFFFF));
return;
}
}
// Give it the most eligible window
if (NULL != (win = gWindowManager->DoGetFrontWindow()))
win->DoKey(key,event->modifiers);
}
void BaseEventManager::HandleKeyUpDispatch(EventRecord *event)
{
}
void BaseEventManager::HandleAutoKeyDispatch(EventRecord *event)
{
HandleKeyDownDispatch(event);
}
void BaseEventManager::HandleUpdateEvtDispatch(EventRecord *event)
{
WindowPtr window;
Window *win;
window = (WindowPtr)event->message;
win = gWindowManager->DoGetWindow(window);
if (win != NULL)
win->DoUpdate();
}
void BaseEventManager::HandleActivateEvtDispatch(EventRecord *event)
{
WindowPtr window;
window = (WindowPtr)event->message;
gWindowManager->DoActivation(window,event->modifiers & activeFlag);
gMenuManager->DoMenuUpdates();
}
void BaseEventManager::HandleOSEvtDispatch(EventRecord *event)
{
// Is this a suspend/resume event?
if ((event->message & 0xFF000000) == 0x01000000)
{
gWindowManager->DoSuspendResume(event,!(event->message & 1));
gMenuManager->DoMenuUpdates();
}
}
void BaseEventManager::HandleHighLevelEventDispatch(EventRecord *event)
{
ProcessAppleEvent(event);
}
void BaseEventManager::HandleDialogEventDispatch(EventRecord *event)
{
WindowPtr window;
DialogPtr dialog;
short item;
Window *win;
win = NULL;
switch(event->what)
{
case mouseDown:
case mouseUp:
FindWindow(event->where,&window);
win = gWindowManager->DoGetWindow(window);
break;
case keyDown:
case keyUp:
case autoKey:
win = gWindowManager->DoGetFrontWindow();
break;
case updateEvt:
window = (WindowPtr)event->message;
win = gWindowManager->DoGetWindow(window);
break;
case activateEvt:
window = (WindowPtr)event->message;
win = gWindowManager->DoGetWindow(window);
HandleActivateEvtDispatch(event);
break;
}
if (win)
win->DoDialogEvent(event);
else
DialogSelect(event,&dialog,&item);
}
void BaseEventManager::HandleInMenuBarDispatch(EventRecord *event)
{
UInt32 selection;
gMenuManager->DoMenuUpdates();
selection = MenuSelect(event->where);
if ((selection >> 16) != 0)
gMenuManager->DoSelect((selection >> 16),(selection & 0xFFFF));
}
void InitAppleEvents(void)
{
AEEventHandlerUPP AECoreProc;
// Install the core AppleEvent handlers.
AECoreProc = NewAEEventHandlerProc(AECoreHandler);
AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,AECoreProc,kAEOpenApplication,false);
AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,AECoreProc,kAEOpenDocuments,false);
AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,AECoreProc,kAEPrintDocuments,false);
AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,AECoreProc,kAEQuitApplication,false);
}
void ProcessAppleEvent(EventRecord *event)
{
AEProcessAppleEvent(event);
}
pascal OSErr AECoreHandler(AppleEvent *aevent,AppleEvent *areply,long refcon)
{
// Dispatch via refcon.
switch(refcon)
{
case kAEOpenApplication:
break;
case kAEOpenDocuments:
break;
case kAEPrintDocuments:
break;
case kAEQuitApplication:
InitiateAppQuit();
break;
}
// Make sure event was properly handled.
return (SInt16)AEGotRequiredParams(aevent);
}
OSStatus AEGotRequiredParams(AppleEvent *aevent)
{
DescType returnedType;
Size actualSize;
OSStatus err;
// Make sure we extracted all the required parameters.
err = AEGetAttributePtr(aevent,keyMissedKeywordAttr,typeWildCard,&returnedType,nil,0,&actualSize);
if (err == errAEDescNotFound)
{
// Got all required parameters.
return noErr;
}
else if (err != noErr)
{
// Missed a required parameter.
return errAEEventNotHandled;
}
// AEGetAttributePtr failed: weird!
return err;
}